<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

define( "JIEQI_MODULE_NAME", "system" );
require_once( "../global.php" );
include_once( JIEQI_ROOT_PATH."/class/power.php" );
$power_handler =& jieqipowerhandler::getinstance( "JieqiPowerHandler" );
$power_handler->getsavedvars( "system" );
jieqi_checkpower( $jieqiPower['system']['adminmessage'], $jieqiUsersStatus, $jieqiUsersGroup, false, true );
jieqi_loadlang( "message", JIEQI_MODULE_NAME );
if ( empty( $_REQUEST['id'] ) )
{
		jieqi_printfail( $jieqiLang['system']['message_no_exists'] );
}
include_once( JIEQI_ROOT_PATH."/class/message.php" );
$message_handler = jieqimessagehandler::getinstance( "JieqiMessageHandler" );
$message = $message_handler->get( $_REQUEST['id'] );
if ( !$message )
{
		jieqi_printfail( $jieqiLang['system']['message_no_exists'] );
}
if ( $message->getvar( "fromid" ) != 0 && $message->getvar( "toid" ) != 0 )
{
		jieqi_printfail( $jieqiLang['system']['message_no_exists'] );
}
include_once( JIEQI_ROOT_PATH."/admin/header.php" );
$jieqiTpl->assign( "messageid", $_REQUEST['id'] );
$jieqiTpl->assign( "title", $message->getvar( "title" ) );
if ( 0 < $message->getvar( "fromid" ) )
{
		$jieqiTpl->assign( "fromid", $message->getvar( "fromid" ) );
		$jieqiTpl->assign( "fromname", $message->getvar( "fromname" ) );
}
else
{
		$jieqiTpl->assign( "fromid", 0 );
		$jieqiTpl->assign( "fromname", "" );
}
if ( 0 < $message->getvar( "toid" ) )
{
		$jieqiTpl->assign( "toid", $message->getvar( "toid" ) );
		$jieqiTpl->assign( "toname", $message->getvar( "toname" ) );
}
else
{
		$jieqiTpl->assign( "toid", 0 );
		$jieqiTpl->assign( "toname", "" );
}
$jieqiTpl->assign( "postdate", date( JIEQI_DATE_FORMAT." ".JIEQI_TIME_FORMAT, $message->getvar( "postdate" ) ) );
include_once( JIEQI_ROOT_PATH."/lib/text/textconvert.php" );
$ts = textconvert::getinstance( "TextConvert" );
$jieqiTpl->assign( "content", $ts->makeclickable( $message->getvar( "content" ) ) );
if ( $message->getvar( "toid" ) == 0 || $message->getvar( "toid" ) == $_SESSION['jieqiUserId'] )
{
		$box = "inbox";
}
else
{
		$box = "outbox";
}
$jieqiTpl->assign( "box", $box );
$jieqiTpl->assign( "url_reply", JIEQI_URL."/newmessage.php?reid=".$_REQUEST['id'] );
$jieqiTpl->assign( "url_forward", JIEQI_URL."/newmessage.php?fwid=".$_REQUEST['id'] );
$jieqiTpl->assign( "url_delete", JIEQI_URL."/message.php?box=".$box."&delid=".$_REQUEST['id'] );
$jieqiTpl->setcaching( 0 );
$jieqiTset['jieqi_contents_template'] = JIEQI_ROOT_PATH."/templates/admin/messagedetail.html";
if ( $message->getvar( "isread" ) != 1 && ( $message->getvar( "toid" ) == 0 || $message->getvar( "toid" ) == $_SESSION['jieqiUserId'] ) )
{
		$message->setvar( "isread", "1" );
		$message_handler->insert( $message );
}
include_once( JIEQI_ROOT_PATH."/admin/footer.php" );
?>
